<?php 
defined('_JEXEC') or die('Restricted access');
$params = &JComponentHelper::getParams( 'com_simplelisting');
$Itemid = JRequest::getVar( 'Itemid', 0, 'get', 'int' );
$ordering = ($this->lists['order'] == 'ordering');
$currencyformat   = $params->get('currency_format');
JHTML::_('behavior.tooltip');
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.path');
JHTML::stylesheet('base.css', JURI::root().'components/com_simplelisting/css/');
JHTML::stylesheet('listing.css', JURI::root().'/components/com_simplelisting/css/themes/'.$this->select_theme.'/');
?>
<script language="javascript" type="text/javascript"></script>
                   
    <div id="listing_details"><!-- Start main container div-->
	<div id="listing_details_inner"><!-- Start inner div -->
            <?php if ( $this->params->get( 'listtitle' ) ) : ?>
                <div class="header">
                   <table class="general_details" width="98%" border="0">
                       <tbody>
                           <tr>
                               <td class="cw_title_main">
                                   <?php echo $this->listtitle; ?>
                               </td>
                           </tr>
                       </tbody>
                   </table>
                </div>
            <div style="width:100%; height:10px;"></div>
            <?php endif; ?>
            <?php if ( $this->params->get( 'show_search' ) ) : ?>
        <div id="cw_filter_cont">
            <span class="search_title">
                <?php echo JText::_( 'FT_SEARCH' ); ?>
            </span>
                <form action="" name="cw_filter" method="post" >
                    <div class="cw_filters">

                                <?php echo $this->lists['fcategory_id'];?>
                                <?php echo $this->lists['ftype_id'];?>
                                <?php if ( $this->params->get( 'show_country_admin' ) ) : ?>
                                    <?php echo $this->lists['fcountry_id'];?>
                                <?php endif ?>
                                <?php if ( $this->params->get( 'show_extras_admin' ) ) : ?>
                                    <?php echo $this->lists['fextra_id'];?>
                                <?php endif ?>
                                <?php if ( $this->params->get( 'show_layout_admin' ) ) : ?>
                                <?php echo $this->lists['flayout_id'];?>
                                <?php endif ?>
                                <?php echo $this->lists['forder_id'];?>
                    </div>
                    <div class="cw_filter_bt">
                        <span class="cw_filter_bt">
                            <input type="submit" value="<?php echo JText::_('BT_FILTER') ?>" class="button" />
                        </span>
                    </div>
                    <input type="hidden" name="task" value="filteritems"/>
                </form>
        </div>
                
                <div style="width:100%; height:10px;"></div>
                <?php endif; ?>

            <form action="" method="post" name="adminForm" ><!-- Start listing form -->
                    <?php
                    $k = 0;
                    for ($i=0, $n=count( $this->items ); $i < $n; $i++)
                    {
                    $row = &$this->items[$i];
                    $link 	= JRoute::_( 'index.php?option=com_simplelisting&task=show&cid[]='.$row->id);
                    {
                    ?>
                <div class="list_container"><!--Start list item container -->
                    <span class="item_title">
                        <a href="<?php echo $link; ?>" title="<?php echo JText::_( 'TT_LISTING_LINK' ); ?>"><?php echo $row->name?></a>
                    </span>
                    <span class="item_id_list">
                        <?php echo JText::_( 'LABEL_REF' ),": ", $row->id; ?>
                    </span>
                    <span class="cw_image_teaser">
                        <?php if ( is_file( JPATH_ROOT.'/components/com_simplelisting/images/gallery/'.$row->id.'/main.jpg' ) ) : ?>
                        <a href="<?php echo $link ?>">
                            <img src="<?php echo JURI::root().'/components/com_simplelisting/images/gallery/'.$row->id.'/main.jpg' ?>" border="0" alt="No Image" height="90" />
                        </a>
                        <?php else: ?>
                        <a href="<?php echo $link ?>">
                        <img src="<?php echo JURI::root().'/components/com_simplelisting/images/nolistings.gif'; ?>" border="0" alt="No Image" title="No Image" height="90" />
                        </a>
                        <?php endif; ?>
                    </span>
                    <span class="cw_item_details">
                        <?php if ( $this->params->get( 'show_price_admin' ) ) : ?>
                            <?php if ( $this->params->get( 'show_price_list' ) ) : ?>
                                <?php if ( $this->params->get( 'price_label' ) ) : ?>
                                    <b><?php echo $this->price_label; ?></b>
                                <?php else :?>
                                    <b><?php echo JText::_('LABEL_PRICE').': '?></b>
                                <?php endif; ?>

                                <?php $number = $row->price;
                                if ($currencyformat==0) {
                                        $formatted_price = number_format($number);
                                } else if ($currencyformat==1) {
                                        $formatted_price = number_format($number,3);
                                } else if ($currencyformat==2) {
                                        $formatted_price = number_format($number, 2,', ',' ');
                                } else if ($currencyformat==3) {
                                        $formatted_price = number_format($number, 2,'.','');
                                }
                                    echo $this->currency,$formatted_price; ?><br />
                                 <?php endif; ?>
                        <?php endif; ?>

                        <?php if ( $this->params->get( 'show_category_list' ) ) : ?>
                            <?php if ( $this->params->get( 'category_label' ) ) : ?>
                                <b><?php echo $this->category_label; ?></b>
                            <?php else :?>
                                <b><?php echo JText::_('LABEL_CATEGORY').': '?></b>
                            <?php endif; ?>
                            <?php echo $this->escape($row->category); ?><br />
                        <?php endif; ?>

                        <?php if ( $this->params->get( 'show_type_list' ) ) : ?>
                            <?php if ( $this->params->get( 'type_label' ) ) : ?>
                                <b><?php echo $this->type_label; ?></b>
                            <?php else :?>
                                <b><?php echo JText::_('LABEL_TYPE').': '?></b>
                            <?php endif; ?>
                            <?php echo $this->escape($row->type); ?><br />
                        <?php endif; ?>

                        <?php if ( $this->params->get( 'show_country_admin' ) ) : ?>
                            <?php if ( $this->params->get( 'show_country_list' ) ) : ?>
                                <?php if ( !empty($row->country) ) { ?>
                                    <?php if ( $this->params->get( 'country_label' ) ) : ?>
                                        <b><?php echo $this->country_label; ?></b>
                                    <?php else :?>
                                        <b><?php echo JText::_('LABEL_COUNTRY').': '?></b>
                                    <?php endif; ?>
                                    <?php echo $this->escape($row->country); ?><br />
                                <?php } ?>
                            <?php endif; ?>
                        <?php endif; ?>

                        <?php if ( $this->params->get( 'show_extras_admin' ) ) : ?>
                            <?php if ( $this->params->get( 'show_extras_list' ) ) : ?>
                                <?php if ( !empty($row->extra) ) { ?>
                                    <?php if ( $this->params->get( 'type_label' ) ) : ?>
                                        <b><?php echo $this->extras_label; ?></b>
                                    <?php else :?>
                                        <b><?php echo JText::_('LABEL_EXTRAS').': '?></b>
                                    <?php endif; ?>
                                    <?php echo $this->escape($row->extra); ?><br />
                                <?php } ?>
                            <?php endif; ?>
                        <?php endif; ?>

                        <?php if ( $this->params->get( 'show_layout_admin' ) ) : ?>
                            <?php if ( $this->params->get( 'show_layout_list' ) ) : ?>
                                <?php if ( !empty($row->layout) ) { ?>
                                    <?php if ( $this->params->get( 'layout_label' ) ) : ?>
                                        <b><?php echo $this->layout_label; ?></b>
                                    <?php else :?>
                                        <b><?php echo JText::_('LABEL_LAYOUT').': '?></b>
                                    <?php endif; ?>
                                    <?php echo $this->escape($row->layout); ?><br />
                                <?php } ?>
                            <?php endif; ?>
                        <?php endif; ?>

                        <?php if ( $this->params->get( 'show_date_list' ) ) : ?>
                            <?php if ( $this->params->get( 'posted_label' ) ) : ?>
                                <b><?php echo $this->posted_label; ?></b>
                            <?php else :?>
                                <b><?php echo JText::_('LABEL_POSTED_DATE').': '?></b>
                            <?php endif; ?>
                            <?php echo JHTML::_('date',  $row->date_created,  JText::_('DATE_FORMAT_LC4') ) ?>
                        <?php endif; ?>
                    </span>

                    <span class="cw_contact_details">
                        <?php if ( $this->params->get( 'show_cont_name_list' ) ) : ?>
                        <b> <?php echo JText::_('LABEL_CONTACT_NAME').': '?></b><?php echo $this->escape( $row->username); ?><br />
                        <?php endif; ?>

                        <?php if ( $this->params->get( 'show_cont_ph_list' ) ) : ?>
                            <?php if ( !empty($row->tel) ) { ?>
                            <b> <?php echo JText::_('LABEL_CONTACT_TELEPHONE').': '?></b><?php echo $this->escape( $row->tel); ?><br />
                            <?php } ?>
                        <?php endif; ?>

                        <?php if ( $this->params->get( 'show_cont_mob_list' ) ) : ?>
                            <?php if ( !empty($row->mobile) ) { ?>
                            <b> <?php echo JText::_('LABEL_CONTACT_MOBILE').': '?></b><?php echo $this->escape( $row->mobile); ?><br />
                            <?php } ?>
                        <?php endif; ?>

                        <?php if ( $this->params->get( 'show_cont_fax_list' ) ) : ?>
                            <?php if ( !empty($row->fax) ) { ?>
                            <b> <?php echo JText::_('LABEL_CONTACT_FAX').': '?></b><?php echo $this->escape( $row->fax); ?><br />
                            <?php } ?>
                        <?php endif; ?>
                            
                        <?php if ( $this->params->get( 'show_cont_email_list' ) ) : ?>
                        <b> <?php echo JText::_('LABEL_CONTACT_EMAIL').': '?></b><?php echo $this->escape( $row->email); ?><br />
                        <?php endif; ?>

                        <?php if ( $this->params->get( 'show_cont_country_list' ) ) : ?>
                            <?php if ( !empty($row->usercountry) ) { ?>
                            <b> <?php echo JText::_('LABEL_CONTACT_COUNTRY').': '?></b><?php echo $this->escape( $row->usercountry); ?><br />
                            <?php } ?>
                        <?php endif; ?>
                    </span>
                    <?php if ( $this->params->get( 'show_dt_bt' ) ) : ?>
                    <span id="detail_button_bottom">
                        <input type="button" onClick="javascript:window.location='<?php echo $link; ?>'" value="<?php echo JText::_('BT_DETAILS'); ?>" class="button" >
                    </span>
                    <?php endif; ?>
                </div><!--End list item container -->

                        <?php
                        }
                            $k = 1 - $k;
                        }
                        ?>
                <input type="hidden" name="view" value="listings" />
                <div id="sl_pagnation">
                    <table class="pagnation" width="100%" border="0">
                       <tbody>
                           <tr>
                               <td>
                                <?php  echo $this->pagination->getListFooter(); ?>
                               </td>      
                           </tr>
                        </tbody>
                    </table>
                </div>
                <input type="hidden" name="option" value="com_simplelisting" />
                <input type="hidden" name="view" value="listings" />
                <input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
                <input type="hidden" name="filter_order_Dir" value="<?php echo $this->lists['order_Dir']; ?>" />
            <?php if ( $this->params->get( 'show_poweredby' ) ) : ?>
                <div class="cw_powerbyfront">
                    <span class="cw_powerbyfront"><?php echo JTEXT::_('POWEREDBY_MSG'); ?> <a href="http://www.celtaweb.com" target="_blank" title="CeltaWeb">CeltaWeb</a> </span>
                </div>
            <?php endif ?>
        </form><!-- End listing form -->
    </div><!-- End inner div -->
</div><!-- End main container div -->
